package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.training.domain.JwMeetingsTraining;
import com.ruoyi.training.service.IJwMeetingsTrainingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议培训情况Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/training/training")
public class JwMeetingsTrainingController extends BaseController
{
    @Autowired
    private IJwMeetingsTrainingService jwMeetingsTrainingService;

    /**
     * 查询会议培训情况列表
     */
    @PreAuthorize("@ss.hasPermi('training:training:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwMeetingsTraining jwMeetingsTraining)
    {
        startPage();
        List<JwMeetingsTraining> list = jwMeetingsTrainingService.selectJwMeetingsTrainingList(jwMeetingsTraining);
        return getDataTable(list);
    }

    /**
     * 导出会议培训情况列表
     */
    @PreAuthorize("@ss.hasPermi('training:training:export')")
    @Log(title = "会议培训情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwMeetingsTraining jwMeetingsTraining)
    {
        List<JwMeetingsTraining> list = jwMeetingsTrainingService.selectJwMeetingsTrainingList(jwMeetingsTraining);
        ExcelUtil<JwMeetingsTraining> util = new ExcelUtil<JwMeetingsTraining>(JwMeetingsTraining.class);
        util.exportExcel(response, list, "会议培训情况数据");
    }

    /**
     * 获取会议培训情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:training:query')")
    @GetMapping(value = "/{mtId}")
    public AjaxResult getInfo(@PathVariable("mtId") Long mtId)
    {
        return success(jwMeetingsTrainingService.selectJwMeetingsTrainingByMtId(mtId));
    }

    /**
     * 新增会议培训情况
     */
    @PreAuthorize("@ss.hasPermi('training:training:add')")
    @Log(title = "会议培训情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwMeetingsTraining jwMeetingsTraining)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwMeetingsTraining.setDeptId(104L);
        jwMeetingsTraining.setUserId(user.getUserId());
        return toAjax(jwMeetingsTrainingService.insertJwMeetingsTraining(jwMeetingsTraining));
    }

    /**
     * 修改会议培训情况
     */
    @PreAuthorize("@ss.hasPermi('training:training:edit')")
    @Log(title = "会议培训情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwMeetingsTraining jwMeetingsTraining)
    {
        return toAjax(jwMeetingsTrainingService.updateJwMeetingsTraining(jwMeetingsTraining));
    }

    /**
     * 删除会议培训情况
     */
    @PreAuthorize("@ss.hasPermi('training:training:remove')")
    @Log(title = "会议培训情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mtIds}")
    public AjaxResult remove(@PathVariable Long[] mtIds)
    {
        return toAjax(jwMeetingsTrainingService.deleteJwMeetingsTrainingByMtIds(mtIds));
    }
}
